/*
 * TiskStartovniListinyDialog.java
 *
 * Created on 24. leden 2007, 16:31
 */

package cz.results.winter6.view.dialogs.stkategorie;

import cz.results.winter6.model.KategorieConfig;
import cz.results.winter6.model.KategorieConfigList;
import cz.results.winter6.model.slmodel.StartListModel;
import java.util.Iterator;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JDialog;

public class TiskStartovniListinyDialog extends javax.swing.JDialog {
    
    private StartListModel startListModel;
    
    public TiskStartovniListinyDialog(JDialog parent, boolean modal, StartListModel startListModel) {
        super(parent, modal);
        
        setStartListModel(startListModel);
        
        initComponents();
        
        naplnJComboBox1();
        naplnJComboBox2();
        
    }
    
    /** naplni JComboBox1 nazvama typu startovni kategorie (kvalifikace, finale, apod...) */
    public void naplnJComboBox1(){
        jComboBox1.setModel(new DefaultComboBoxModel());
        
        Iterator iterator = getStartListModel().getZavod().getStartovniKategorieConfigMap().keySet().iterator();
        while(iterator.hasNext()){
            String nazevTypuStartovniKaegorie = (String) iterator.next();
            ((DefaultComboBoxModel)jComboBox1.getModel()).addElement(nazevTypuStartovniKaegorie);
        }
    }
    
    /** naplni JComboBox2 nazvama kategorii */
    public void naplnJComboBox2(){
        jComboBox2.setModel(new DefaultComboBoxModel());
        
        Iterator iterator = getStartListModel().getZavod().getKategorieConfigList((String)jComboBox1.getSelectedItem()).iterator();
        while(iterator.hasNext()){
            KategorieConfig kategorieConfig = (KategorieConfig) iterator.next();
            ((DefaultComboBoxModel)jComboBox2.getModel()).addElement(kategorieConfig.getNazev());
        }
    }
    
    
    
    public StartListModel getStartListModel() {
        return startListModel;
    }
    
    public void setStartListModel(StartListModel startListModel) {
        this.startListModel = startListModel;
    }
    
    
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jButtonTiskAll = new javax.swing.JButton();
        jButtonTiskKategorie = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setLocationByPlatform(true);
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jButtonTiskAll.setText("tisk - all");
        jButtonTiskAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTiskAllActionPerformed(evt);
            }
        });

        jButtonTiskKategorie.setText("tisk - kategorie");
        jButtonTiskKategorie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTiskKategorieActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/results/winter6/view/icons/button_cancel.png")));
        jButton3.setText("zav\u0159i");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonTiskAll, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGap(43, 43, 43)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonTiskKategorie, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jComboBox2, 0, 163, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(159, 159, 159))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonTiskAll)
                    .addComponent(jButtonTiskKategorie))
                .addGap(37, 37, 37)
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_jButton3ActionPerformed
    
    private void jButtonTiskKategorieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTiskKategorieActionPerformed
        KategorieConfigList kategorieConfigList = getStartListModel().getZavod().getKategorieConfigList((String)jComboBox1.getSelectedItem());
        KategorieConfig kategorieConfig = getStartListModel().getZavod().getKategorieConfig((String)jComboBox1.getSelectedItem(), jComboBox2.getSelectedIndex());
        
        getStartListModel().doStartovkaPdfZobraz(kategorieConfigList, kategorieConfig);
    }//GEN-LAST:event_jButtonTiskKategorieActionPerformed
    
    private void jButtonTiskAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTiskAllActionPerformed
        getStartListModel().doStartovkaPdfZobraz((String)jComboBox1.getSelectedItem());
    }//GEN-LAST:event_jButtonTiskAllActionPerformed
    
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        naplnJComboBox2();          //kdyz vyberu nejakej typ kategorie, tak musim aktualizovat druhej combobox o nove kategorie...
    }//GEN-LAST:event_jComboBox1ActionPerformed
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButtonTiskAll;
    private javax.swing.JButton jButtonTiskKategorie;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    // End of variables declaration//GEN-END:variables
    
}
